from flask import Flask,redirect,url_for,request
import pymysql

app = Flask(__name__, static_folder='static')
db = pymysql.connect(host='localhost', user='root', password='123456', database='film')
cursor = db.cursor()

@app.route('/novelinfo',methods=['POST'])
def novel():
    novelname = request.form['novelname']
    query_type = request.form.get('query_type', 'author')
    if query_type == 'cover':
        return redirect(url_for('static', filename=novelname+'.jpg'))
    sql = "select " + query_type + " from xiaoshuo where bookname = '%s'" % (novelname)
    cursor.execute(sql)
    result = cursor.fetchone()
    field_name = {'authorname': '作者', 'updatetime': '更新时间', 'totalwords': '字数'}[query_type]
    return novelname + '的' + field_name + '是' + str(result[0])

if __name__=='__main__':
    app.run(debug=True,host='127.0.0.1' , port=1234)